﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var name =TextBox1.Text.Trim();
            var pwd = TextBox2.Text.Trim();
            var sql = string.Format("select * from Users where Username='{0}'", name);
            var dt = DbHelper.GetDataTable(sql);
            if (dt.Rows.Count > 0)
            {
                var item = dt.Rows[0];
                var isActive = (bool)item.ItemArray[3];
                var isDelete = (bool)item.ItemArray[4];
                var password = item.ItemArray[2].ToString();
                if (isDelete)
                {
                    Response.Write("<script>alert('该帐户已被删除')</script>");

                }
                else
                {
                    if (isActive)
                    {
                        if (pwd == password)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert('用户名或密码错误')</script>;");
                        }
                    }

                    else
                    {
                        Response.Write("<script>alert('当前用户已被删除或冻结');</script>");
                    }
                }

            }
            else
            {
                Response.Write("<script>alert('当前用户 未注册');</script>");
            }
        


    }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }
    }
}